﻿
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UCViewTable1.ascx.cs"
    Inherits="Phong_CTSV.UCViewTable1" %>

    <% 
    bool hasRowsHeader = formInfo.Has_rows;
    
%>


<div class="title">
    <h1>
        <% Response.Write(NameTable); %>
    </h1>
</div>
<div class="scroll">
<table class="clientForm">
    <thead>
        <tr>
            <%  int index = 0;
                // PARENT COLUMN HEADER GENERATE
                foreach (Phong_CTSV.Columns_Header ch in ColumnsHeaderList)
                {
                    if (ch.Parent_id == 0)
                    {
                        int child = 0;
                        foreach (Phong_CTSV.Columns_Header childHeader in ColumnsHeaderList)
                        {
                            if (childHeader.Parent_id == ch.ID)
                            {
                                child++;
                            }
                        }
                
            %>
            <td <%  if (child==0) {Response.Write("rowspan=2");} else {Response.Write("colspan="+child);} %>
                class="<% if (index%2==0) { Response.Write("even");} else { Response.Write("odd");} %>">
                <%Response.Write(ch.Name);%>
            </td>
            <%
index++;
                    }
                }
            %>
        </tr>
        <tr>
            <%
                index = 0;
                //CHILD COLUMN HEADER
                foreach (Phong_CTSV.Columns_Header ch in ColumnsHeaderList)
                {
                    if (ch.Parent_id != 0)
                    {
            %>
            <td class="<% if (index%2==0) { Response.Write("sub-even"); } else { Response.Write("sub-odd");} %>">
                <%Response.Write(ch.Name); %>
            </td>
            <%      
                }//if
                    index++;
                }
                //foreach
            %>
        </tr>
    </thead>
    <tbody>
        <%
        
            // ROW HEADER GENERATE
            int rowIndex = 0;
            if (formInfo.Has_rows)
            {
                foreach (Phong_CTSV.Rows_Header rh in RowsHeaderList)
                {
        %>
        <tr class="<% if (index%2==0) { Response.Write("even");} else { Response.Write("odd");} %>">
            <% if (hasRowsHeader)
               { %>
            <td>
                <%Response.Write(rh.Name);%>
            </td>
            <%} //if
               for (int i = 0; i < NumColumn; i++)
               {
            %>
            <td>
                <%Response.Write(DataTable[rowIndex, i].Value); %>
            </td>
            <%
               
}
            %>
        </tr>
        <%
rowIndex++;
index++;
                }
            }
            else
            {
                for (int i = 0; i < NumRow; i++)
                {
                    %>
                    <tr>
                    
                   
                    <%
                    for (int j = 0; j < NumColumn; j++)
                    {
                        %>
                         <td>
               <%Response.Write(DataTable[i, j].Value); %>
            </td>
                        <%
                    }
                    %>
                     </tr>
                    <%
                }
            }
          
        %>
        <tr class="sum">
            <td>
                TỔNG
            </td>
            <%foreach (var item in Sum)
              {%>
            <td>
               <%Response.Write(item.Value); %>
            </td>
            <%} %>
        </tr>

    </tbody>
</table>
</div>